/*!
 * TidyBlog 2.0
 * Captcha - v1.0.0 (2013-10-05T13:20:59+0800)
 * https://code.google.com/p/tidyblog/ | Released under MIT license
 */
define(function(require, exports, module) { 'use strict';

var widget = require('widget/1.0.x/'), tmpl = require('tmpl/1.0.x/');

return widget.create(function() {

}, {
	_init: function(options) {
		var wrapper = this._wrapper = options.wrapper;
		this._src = wrapper.attr('data-src');
		this._bgColor = wrapper.attr('data-bgcolor');
		this._formName = wrapper.attr('data-formname');
		this.refresh();
	},
	_destroy: function() {
		this._wrapper.empty();
		delete this._wrapper;
		delete this._src;
		delete this._bgColor;
		delete this._formName;
	},
	refresh : function() {
		var t = this;
		t._wrapper.empty().html(
			tmpl.render(
				'<img src="<%=src%>?bgColor=<%=bgColor%>&formName=<%=formName%>&ts=<%=ts%>" alt="点击更换验证码" class="captcha-img" />',
				{
					src: t._src,
					bgColor: t._bgColor,
					formName: t._formName,
					ts: +new Date
				}
			)
		).find('img').click(function() { t.refresh(); });
	}
});

});